package com.kefu.robot.service;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.kefu.robot.vo.RobotDocNodeItemQuestionInsertVo;
import com.kefu.robot.vo.RobotDocNodeItemQuestionUpdateVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.kefu.common.service.AbstractKefuService;
import com.kefu.robot.mapper.RobotDocNodeItemQuestionMapper;
import com.kefu.robot.model.RobotDocNodeItemQuestion;

import java.util.List;

/**
 * @author xiaoyu
 * @date 2023/02/24
 */
@Service
public class RobotDocNodeItemQuestionService extends AbstractKefuService<RobotDocNodeItemQuestion> {
    @Autowired
    protected RobotDocNodeItemQuestionMapper robotDocNodeItemQuestionMapper;

    public void addRobotDocNodeItemQuestion(RobotDocNodeItemQuestionInsertVo robotDocNodeItemQuestionInsertVo) {
        robotDocNodeItemQuestionInsertVo.getQuestionList().forEach(insertVo -> {
            RobotDocNodeItemQuestion question = robotDocNodeItemQuestionInsertVo.convert();
            question.setQuestion(insertVo);
            robotDocNodeItemQuestionMapper.insert(question);
        });
    }

    public void updateIteamQuestion(RobotDocNodeItemQuestionUpdateVo robotDocNodeItemQuestionUpdateVo) {
        robotDocNodeItemQuestionMapper.delete(Wrappers.lambdaQuery(RobotDocNodeItemQuestion.class)
                .eq(RobotDocNodeItemQuestion::getItemId, robotDocNodeItemQuestionUpdateVo.getItemId()));
        robotDocNodeItemQuestionUpdateVo.getQuestionList().forEach(update -> {
            RobotDocNodeItemQuestion info = robotDocNodeItemQuestionUpdateVo.convert();
            info.setQuestion(update);
            robotDocNodeItemQuestionMapper.insert(info);
        });
    }

    public List<RobotDocNodeItemQuestion> ItemQuestionDatialByItemId(String itemId) {
        List<RobotDocNodeItemQuestion> list = robotDocNodeItemQuestionMapper.selectList(Wrappers.lambdaQuery(RobotDocNodeItemQuestion.class)
                .eq(RobotDocNodeItemQuestion::getItemId, itemId));
        return list;
    }
}